package com.jy.appmarket.model;

import android.os.Parcel;
import android.os.Parcelable;

import com.jy.app.market.idata.data.UpdateInfo;

public class AppUpdateModel extends UpdateInfo implements Parcelable {
	private static final long serialVersionUID = 2593138375134508771L;
	private long _id;
	/**
	 * 数据库字段最后变更时间
	 */
	private long lastModification;
	private boolean ignore;

	public AppUpdateModel() {

	}

	public AppUpdateModel(AppUpdateModel model) {
		setTitle(model.getTitle());
		setDownloadUrl(model.getDownloadUrl());
		setIconPath(model.getIconPath());
		setPackageName(model.getPackageName());
		setVersionCode(model.getVersionCode());
		setVersionName(model.getVersionName());
		setFileMd5(model.getFileMd5());
		setChangeLog(model.getChangeLog());
		setSize(model.getSize());
		setLastModified(model.getLastModified());

		setLastModification(model.getLastModification());
		setIgnore(model.isIgnore());

	}

	public AppUpdateModel(UpdateInfo info) {
		setTitle(info.getTitle());
		setDownloadUrl(info.getDownloadUrl());
		setIconPath(info.getIconPath());
		setPackageName(info.getPackageName());
		setVersionCode(info.getVersionCode());
		setVersionName(info.getVersionName());
		setFileMd5(info.getFileMd5());
		setChangeLog(info.getChangeLog());
		setSize(info.getSize());
		setLastModified(info.getLastModified());
	}

	public AppUpdateModel(String name, String downloadUrl, String iconUrl, String packageName,
			int versionCode, String versionName, String md5, String changeLog, long size,
			long lastModified) {
		setTitle(name);
		setDownloadUrl(downloadUrl);
		setIconPath(iconUrl);
		setPackageName(packageName);
		setVersionCode(versionCode);
		setVersionName(versionName);
		setFileMd5(md5);
		setChangeLog(changeLog);
		setSize(size);
		setLastModified(lastModified);
	}

	public long get_id() {
		return _id;
	}

	public void set_id(long _id) {
		this._id = _id;
	}

	/**
	 * 数据库字段最后变更时间
	 */
	public long getLastModification() {
		return lastModification;
	}

	/**
	 * 数据库字段最后变更时间
	 */
	public void setLastModification(long lastModification) {
		this.lastModification = lastModification;
	}

	public boolean isIgnore() {
		return ignore;
	}

	public void setIgnore(boolean ignore) {
		this.ignore = ignore;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeLong(_id);
		dest.writeLong(lastModification);
		dest.writeInt(ignore ? 1 : 0);
		dest.writeString(getTitle());
		dest.writeString(getDownloadUrl());
		dest.writeString(getIconPath());
		dest.writeString(getPackageName());
		dest.writeInt(getVersionCode());
		dest.writeString(getVersionName());
		dest.writeString(getFileMd5());
		dest.writeString(getChangeLog());
		dest.writeLong(getSize());
		dest.writeLong(getLastModified());
		// private RecommendType isRecommended;
		// private NotRecommendReasonType notRecommendedReason;
		dest.writeInt(isSuperior() ? 1 : 0);

	}

	public static final Parcelable.Creator<AppUpdateModel> CREATOR = new Parcelable.Creator<AppUpdateModel>() {
		@Override
		public AppUpdateModel createFromParcel(Parcel source) {
			AppUpdateModel am = new AppUpdateModel();
			am.set_id(source.readLong());
			am.setLastModification(source.readLong());
			am.setIgnore(source.readInt() == 1);
			am.setTitle(source.readString());
			am.setDownloadUrl(source.readString());
			am.setIconPath(source.readString());
			am.setPackageName(source.readString());
			am.setVersionCode(source.readInt());
			am.setVersionName(source.readString());
			am.setFileMd5(source.readString());
			am.setChangeLog(source.readString());
			am.setSize(source.readLong());
			am.setLastModified(source.readLong());
			return am;
		}

		@Override
		public AppUpdateModel[] newArray(int size) {
			return new AppUpdateModel[size];
		}
	};
}
